#include"calculator.h"
#include<fstream>
using namespace std;

int main()
{
    ifstream in_file;
    ofstream out_file;
    in_file.open("input.txt");
    out_file.open("output");
    string input;
    char tmp;
    getline(in_file,input);
    while(in_file)
    {
        out_file<<input<< "-->";
        for (int i = 0; i < input.length(); i++){
            tmp = input[i];
            if(!isoperator(tmp)){
                if((tmp >= '0' && tmp <= '9') || tmp == '.'){
                    ReadNum(tmp);
                    out_file<<tmp;
                }
            }
            else{
                if(i!=0){
                    if(!isoperator(input[i-1])){
                        PushNum();
                        ResetNum();
                        if(tmp != '(' && tmp !=')')
                            out_file<<tmp;
                    }
                }

                if(tmp == '('){
                    BrackerStack.push('(');
                    out_file<<tmp;
                    }
                else if(tmp == ')'){
                    Bracket();
                    out_file<<tmp;
                    }
                else {
                    OpPriority(tmp);
                    }
            }
        }
        if(input[input.length()-1]!= ')'){
            PushNum();
            ResetNum();
            Bracket();
        }
        while(!BrackerStack.isempty())
        {Bracket();}

        float ans = NumStack.pop();
        out_file<<" = "<<ans<<endl;
        getline(in_file,input,'\n');
    }
    in_file.close();
    out_file.close();
}
